package com.his.controller;

import com.his.common.core.controller.BaseController;
import com.his.common.core.domain.AjaxResult;
import com.his.common.core.page.TableDataInfo;
import com.his.entity.dto.Register;
import com.his.service.IClinicService;
import com.his.entity.vo.RegisterVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.his.common.utils.PageUtils.startPage;


@RestController
@RequestMapping("/clinic")
public class ClinicController extends BaseController {
    @Autowired
    private IClinicService clinicService;

    /**
     * 统计今日已就诊人数
     *
     * @return
     */
    @GetMapping("/seen")
    public AjaxResult seen(){
        return AjaxResult.success(clinicService.seen());
    }

    /**
     * 统计今日排队人数
     *
     * @return
     */
    @GetMapping("/queue")
    public AjaxResult queue() {
        return AjaxResult.success(clinicService.queue());
    }

    /**
     * 患者列表
     *
     * @param register
     * @return
     */
    @GetMapping("/patient/list")
    public TableDataInfo list(Register register) {
        startPage();
        List<RegisterVO> list = clinicService.selectClinicRegistList(register);
        return getDataTable(list);
    }

    /**
     * 跳过患者
     *
     * @param registerId
     * @return
     */
    @PutMapping("/skip/{registerId}")
    public AjaxResult skipPatient(@PathVariable String registerId) {
        try {
            clinicService.skipPatient(registerId);
            return AjaxResult.success("患者已跳过，移至队列末尾");
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }
}
